
//全局变量
var imgArray = ["img/index/dt.jpg","img/index/dt2.jpg"];
var visibility = ["hidden","visible"];
var i = 0 ;
var ids = 0;
var clearTimeImg ;
var clearIntervaImg=0;

//加载就运行
window.onload = function(){
    /* 头部js */
    heardShow();
    /* index */
    /* 轮播 */
    $("#lunbo_img").attr('src',imgArray[0])
    lunbo();
    hoverImg();
    setInterval(function(){
        time_dis('1995-10-30 18:06:06')
    },1000)
    /* 手机端轮播 */
    $(window).resize(function(){
        if($(window).width() <= 800 && clearIntervaImg == 0){
            phone_img();
            hoverphoneImg();
        }else if($(window).width() > 800){
            clearInterval(clearIntervaImg);
            clearIntervaImg = 0;
        }
    })
    /* 滚动条动画 */
    getD0MTop();
    //点击查看详情
    goodsClick($("#goodsClick li"));
    goodsClick($("#homegoodsClick li"));
    //初始化购物车数量
    allNumberCountent();
}

/* 轮播 */
//定时方法
function lunbo(){
    clearTimeImg = setTimeout(function(){
        i = i == 0?1:0;
        public_img(-10)
        lunbo();
    },5000)
}

//左边按钮
function leftImg(){
    i = i == 0?1:0;
    public_img(-10)
}

//右边按钮
function rightImg(){
    i = i == 0?1:0;
    public_img(10)
}

//点击点
function clickImg(index){
    i = index;
    public_img(-10);
}

//鼠标悬停事件
function hoverImg(){
    $('.lunbo').hover(function(){
        clearTimeout(clearTimeImg);
    },function(){
        i = i == 0?1:0;
        public_img(-10);
        lunbo();
    })
}

//轮播方法
function public_img(left_whith){
    //文字淡出
    $("#huayu_id").fadeOut(500);
    //切换图片并滑动（需要整理）
    $("#lunbo_img").animate({left:left_whith},function(){
        $("#lunbo_img").css('left','0px');
        //更换图片
        $("#lunbo_img").attr('src',imgArray[i]);
        //更换点得颜色
        $('.dian_ul li').css({'background-color':'rgba(20, 18, 18, 0.7)','border':'0.3rem solid rgba(255,255,255,0.1)'})
        $('.dian_ul li').eq(i).css({'background-color':'#fff','border':'0.3rem solid rgba(1,1,1,0.7)'})
        //文字淡入
        $("#huayu_id").fadeIn(500);
    })
}

/* 报时显示 */
function time_dis (direct_time) {
    // direct_time格式为yyyy-mm-dd hh:mm:ss 指定时间
    var now_time = Date.parse(new Date());//当前时间的时间戳
    var end_time = Date.parse(new Date(direct_time));//指定时间的时间戳
      //计算相差天数
      var time_dis = now_time - end_time ;
      var days=Math.floor(time_dis/(24*3600*1000));
      //计算出小时数
      var leave1=time_dis%(24*3600*1000);//计算天数后剩余的毫秒数
      var hours=Math.floor(leave1/(3600*1000));
      //计算相差分钟数
      var leave2=leave1%(3600*1000);//计算小时数后剩余的毫秒数
      var minutes=Math.floor(leave2/(60*1000));
      //计算相差秒数
      var leave3=leave2%(60*1000);//计算小时数后剩余的毫秒数
      var second = leave3/1000;
      $('.time').eq(0).html(days);
      $('.time').eq(1).html(hours);
      $('.time').eq(2).html(minutes);
      $('.time').eq(3).html(second);
      $('.time').eq(4).html(days);
      $('.time').eq(5).html(hours);
      $('.time').eq(6).html(minutes);
      $('.time').eq(7).html(second);
      return days+"天"+hours+"小时"+minutes+"分"+second+"秒";
  }


/* 产品手机端轮播 */

//轮播方法
function phone_img(){
    clearIntervaImg = setInterval(function(){
        ids ++;
        if(ids > 3){
            ids = 0;
        }
        pubilc_phone_img();

    },5000)
}

function clickPhoneImg(id){
    ids = id;
    pubilc_phone_img();
}

//鼠标悬停事件
function hoverphoneImg(){
    $('.todayNew_dian_ul').hover(function(){
       clearInterval(clearIntervaImg);
       clearIntervaImg = 0;
    },function(){
        ids ++;
        if(ids > 3){
            ids = 0;
        };
        phone_img();
    })
}

//公共方法
function pubilc_phone_img(){
    var fistLi = $('#'+ids);
    $('.todayNew_ul').prepend(fistLi);
    //更换点得颜色
    $('.todayNew_dian_ul li').css({'background-color':'rgba(0,0,0,0.4)'})
    $('.todayNew_dian_ul li').eq(ids).css({'background-color':'#007aff'})
}


